package com.gcxy.shop.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gcxy.shop.domain.Shop;
import com.gcxy.shop.service.ShopService;

@WebServlet(urlPatterns="/index.do")
public class ShopSearchServlet extends HttpServlet{
	
	private static final long serialVersionUID = 1L;
	private Logger logger=LoggerFactory.getLogger(getClass());
	private ShopService shopService=new ShopService();
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		doPost(request, response);
	}

	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		logger.debug("开始执行dopost");
		try {
			String productname=request.getParameter("productname");
			productname=productname==null?"":productname;//把空值转换为空串
			Shop shop=new Shop();
			shop.setProductname(productname);
			
			
			List<Shop> shops=shopService.findPager(shop);
			//跳转
			request.setAttribute("shops",shops);
			request.getRequestDispatcher("/index.jsp").forward(request, response);
		} catch (Exception e) {
			e.printStackTrace();
			request.setAttribute("error", e.getMessage());
			request.getRequestDispatcher("/index.jsp").forward(request, response);
			logger.error("新闻分页查询失败:{}",e.getMessage());
		}
	}

	

}
